package com.furentech.iotserver.fa.server;

import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import org.springframework.util.Assert;

public class ChannelUtil {

    public static Channel currentChannel;


    public static void setCurrentChannel(Channel channel)
    {
        currentChannel=channel;
    }

    //设置通道的devId
    public static void setChannelFrameNumber(Channel channel, Byte frameNumber) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.FRAME_NUMBER).set(frameNumber);
    }

    public static Byte getChannelFrameNumber(Channel channel)
    {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.FRAME_NUMBER).get();
    }


    public static void setChannelDevSourceAddr(Channel channel, Byte addr) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.DEV_SOURCE_ADDR).set(addr);
    }

    public static Byte getChannelDevSourceAddr(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.DEV_SOURCE_ADDR).get();
    }


    public static Boolean getReqVTotFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_V_TOT_FLAG).get();
    }

    public static void setReqVTotFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_V_TOT_FLAG).set(flag);
    }

    public static Boolean getReqDispenserInfoFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_DISPENSER_INFO_FLAG).get();

    }

    public static void setReqDispenserInfoFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_DISPENSER_INFO_FLAG).set(flag);
    }

    public static Boolean getCbRecordFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.CB_RECORD_FLAG).get();
    }

    public static void setCbRecordFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.CB_RECORD_FLAG).set(flag);
    }

    public static Boolean getAuthReq2Flag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.AUTH_REQ2_FLAG).get();
    }

    public static void setAuthReq2Flag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.AUTH_REQ2_FLAG).set(flag);
    }

    public static Byte[] getAuthReq2RespBuf(Channel channel)
    {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.AUTH_REQ2_RESPONSE_BUF).get();
    }

    public static void setAuthReq2RespBuf(Channel channel,Byte[] buf) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.AUTH_REQ2_RESPONSE_BUF).set(buf);
    }



    public static Boolean getReqSignInFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_SIGN_IN_FLAG).get();
    }

    public static void setReqSignInFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_SIGN_IN_FLAG).set(flag);
    }

    public static Byte[] getReqSignInRespBuf(Channel channel)
    {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_SIGN_IN_RESP_BUF).get();
    }

    public static void setReqSignInRespBuf(Channel channel,Byte[] buf) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_SIGN_IN_RESP_BUF).set(buf);
    }


    public static Boolean getReqOnlineFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_ONLINE_FLAG).get();
    }

    public static void setReqOnlineFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_ONLINE_FLAG).set(flag);
    }

    public static Byte[] getReqOnlineRespBuf(Channel channel)
    {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_ONLINE_RESP_BUF).get();
    }

    public static void setReqOnlineRespBuf(Channel channel,Byte[] buf) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_ONLINE_RESP_BUF).set(buf);
    }


    public static Boolean getReqDebitFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_DEBIT_FLAG).get();
    }

    public static void setReqDebitFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_DEBIT_FLAG).set(flag);
    }

    public static Byte[] getReqDebitRespBuf(Channel channel)
    {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_DEBIT_RESP_BUF).get();
    }

    public static void setReqDebitRespBuf(Channel channel,Byte[] buf) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_DEBIT_RESP_BUF).set(buf);
    }


    public static Boolean getReqReverseFlag(Channel channel) {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_REVERSE_FLAG).get();
    }

    public static void setReqReverseFlag(Channel channel, Boolean flag) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_REVERSE_FLAG).set(flag);
    }

    public static Byte[] getReqReverseRespBuf(Channel channel)
    {
        Assert.notNull(channel,"channel==null");
        return channel.attr(ChannelAttributes.REQ_REVERSE_RESP_BUF).get();
    }

    public static void setReqReverseRespBuf(Channel channel,Byte[] buf) {
        Assert.notNull(channel,"channel==null");
        channel.attr(ChannelAttributes.REQ_REVERSE_RESP_BUF).set(buf);
    }


}
